package com.secondDay;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test17 {
    public static void main(String[] args) throws UnknownHostException {

        /**
         * static InetAddress getByName(String host)    确定主机名称的IP地址,主机名称可以是机器名称,也可以是IP地址
         * String getHostName()                         获取此IP地址的主机名
         * String getHostAddress()                      返回文本显示中的IP地址字符串
         */

        // 1. 获取InetAddress的对象
        // IP的对象   一台电脑的对象
        InetAddress address = InetAddress.getByName("127.0.0.1"); //   /127.0.0.1
        System.out.println(address);

        // 这个名称是,点击此电脑,右边空白处,右击鼠标,选择属性,之后就有主机名了
        InetAddress inetAddress = InetAddress.getByName("LAPTOP-SQHLP057");
        System.out.println(inetAddress); // LAPTOP-SQHLP057/192.168.110.37

        String hostName = address.getHostName();
        System.out.println(hostName); // activate.navicat.com

        String ip = address.getHostAddress();
        System.out.println(ip); // 127.0.0.1

    }
}



















